home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Misc / Wood.0.72 / Sources / WoodDoc_ValidateMenuCells.m < prev    next >
Encoding:
Text File  |  1995-07-29  |  3.2 KB  |  126 lines

  1. #import "wooddoc.h"
  2.  
  3. @implementation WoodDoc (ValidateMenuCells)
  4.  
  5. - (BOOL)validateCommand:menuCell
  6. {
  7.     SEL action = [menuCell action];
  8.     BOOL redraw = NO, enabled = [menuCell isEnabled];
  9.     char buffer[100];
  10.  
  11.     if(action == @selector(revertToSaved:)){ 
  12.         if(!enabled && [self needsSaving] && [self hasSavedDocument]){
  13.             [menuCell setEnabled:YES];
  14.             redraw = YES;
  15.         } else if(enabled && (![self needsSaving] || ![self hasSavedDocument])){
  16.             [menuCell setEnabled:NO];
  17.             redraw = YES;
  18.         };
  19.     } else if(action == @selector(save:) || action == @selector(saveAs:) 
  20.             || action == @selector(print:) || action == @selector(saveTo:)){
  21.         if(!enabled){
  22.             [menuCell setEnabled:YES];
  23.             redraw = YES;
  24.         }
  25.     } else if(action == @selector(changeZip:)){
  26.         if(lastSelectedNode){
  27.             if(!enabled){
  28.                 redraw = YES;
  29.                 [menuCell setEnabled:YES];
  30.             }
  31.             if([lastSelectedNode zipped] && strcmp([menuCell title], "Expand")){
  32.                 [menuCell setTitle:"Expand"];
  33.                 redraw = YES;
  34.             } else if(![lastSelectedNode zipped] && strcmp([menuCell title], "Collapse")){
  35.                 [menuCell setTitle:"Collapse"];
  36.                 redraw = YES;
  37.             }
  38.         } else if(enabled){
  39.             [menuCell setEnabled:NO];
  40.             redraw = YES;
  41.         } 
  42.     } else if(action == @selector(copy:) || action == @selector(cut:) 
  43.             || action == @selector(delete:) || action == @selector(copyStyle:) 
  44.             || action == @selector(pasteStyle:) || action == @selector(promoteStyle:)){
  45.         if(lastSelectedNode){
  46.             if(!enabled){
  47.                 [menuCell setEnabled:YES];
  48.                 redraw = YES;
  49.             }
  50.         } else {
  51.             if(enabled){
  52.                 [menuCell setEnabled:NO];
  53.                 redraw = YES;
  54.             }
  55.         }
  56.     } else if(action == @selector(paste:) || action == @selector(add:) 
  57.            || action == @selector(addFromFilter:)){
  58.         if(lastSelectedNode || !tree){
  59.             if(!enabled){
  60.                 [menuCell setEnabled:YES];
  61.                 redraw = YES;
  62.             }
  63.         } else {
  64.             if(enabled){
  65.                 [menuCell setEnabled:NO];
  66.                 redraw = YES;
  67.             }
  68.         }
  69.     } else if(action == @selector(changeDescription:)){
  70.         if(lastSelectedNode && !textViewSaved){
  71.             if(!enabled){
  72.                 redraw = YES;
  73.                 [menuCell setEnabled:YES];
  74.             }
  75.         } else if(enabled){
  76.             [menuCell setEnabled:NO];
  77.             redraw = YES;
  78.         } 
  79.     } else if(action == @selector(toggleMarker:)){
  80.         if(!enabled){
  81.             redraw = YES;
  82.             [menuCell setEnabled:YES];
  83.         }
  84.         if(showMarker && !strcmp([menuCell title], "Show Marker")){
  85.                 [menuCell setTitle:"Hide Marker"];
  86.                 redraw = YES;
  87.         } else if(!showMarker && !strcmp([menuCell title], "Hide Marker")){
  88.                 [menuCell setTitle:"Show Marker"];
  89.                 redraw = YES;
  90.         } 
  91.     }  else if(action == @selector(undo:)){
  92.         if([undoManager lastUndoName]){
  93.             if(!enabled){
  94.                 redraw = YES;
  95.                 [menuCell setEnabled:YES];
  96.             }
  97.             sprintf(buffer,"Undo %s",[undoManager lastUndoName]);
  98.             if(strcmp([menuCell title], buffer)){
  99.                 redraw = YES;
  100.                 [menuCell setTitle:buffer];
  101.             }
  102.         } else if(enabled){
  103.             [menuCell setEnabled:NO];
  104.             redraw = YES;
  105.         } 
  106.     } else if(action == @selector(redo:)){
  107.         if([undoManager lastRedoName]){
  108.             if(!enabled){
  109.                 redraw = YES;
  110.                 [menuCell setEnabled:YES];
  111.             }
  112.             sprintf(buffer,"Redo %s",[undoManager lastRedoName]);
  113.             if(strcmp([menuCell title], buffer)){
  114.                 redraw = YES;
  115.                 [menuCell setTitle:buffer];
  116.             }
  117.         } else if(enabled){
  118.             [menuCell setEnabled:NO];
  119.             redraw = YES;
  120.         } 
  121.     }
  122.     return redraw;
  123. }
  124.  
  125. @end
  126.